package com.syq.controller;

import com.syq.dto.R;
import com.syq.dto.UserDto;
import com.syq.pojo.SysUserInfo;
import com.syq.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author Sun Yueqi
 * @version 1.00
 * @time 2022/5/25 20:34
 */
@RestController
@RequestMapping("/sysusers")
public class SysUserController {

    private SysUserService sysUserService;

    @Autowired
    public void setSysUserService(SysUserService sysUserService) {
        this.sysUserService = sysUserService;
    }

    //添加用户
    @PostMapping("/user")
    public R register(@RequestBody UserDto userDto){
        sysUserService.addUser(userDto);
        return R.setOk();
    }

    @PostMapping("/login")
    public R login(@RequestBody UserDto userDto, HttpSession session){
        SysUserInfo userInfo = sysUserService.login(userDto);
        session.setAttribute("user",userInfo);
        return R.setOk();
    }
}
